package com.groupnections.server.database.entities;

import java.util.ArrayList;
import java.util.List;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.Objectify;
import com.groupnections.server.database.ObjectifyServiceCreation;
import com.groupnections.shared.Entity;

public class ConnectEntity {

	public static Entity save(Entity entity, String entityID) {

		Objectify objfyService = ObjectifyServiceCreation.gerService();

		List<Key<Entity>> connections = entity.getEntitiesRelated();

		if (connections == null) {

			connections = new ArrayList<Key<Entity>>();
		}

		connections.add(new Key<Entity>(Entity.class, entityID));

		entity.setEntitiesRelated(connections);

		objfyService.put(entity);

		return entity;
	}
}